/*
 * @lc app=leetcode.cn id=26 lang=javascript
 *
 * [26] 删除有序数组中的重复项
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function (nums) {
  if (!nums.length) return 0;

  let start = 0;
  let end = 0;
  let i = 1;
  while (i < nums.length) {
    if (nums[i] !== nums[end]) {
      nums[end + 1] = nums[i];
      end++;
    }
    i++;
  }
  return end - start + 1;
};
// @lc code=end
